import reshandler from 'services/response-handler'
/**
 * 商品评价列表
 * @return response 评论类型: {
 *  all         全部
 *  imageCount  有图
 *  moderate    中评
 *  negative    差评
 *  positive    好评
 *  reviews     评论List
 * }
 */
function makeData(response) {
  return Object.assign({}, response, {
    all: response.all || 0,
    imageCount: response.imageCount || 0,
    moderate: response.moderate || 0,
    negative: response.negative || 0,
    positive: response.positive || 0,
    reviews: response.reviews || []
  })
}

export default function (params, success, fail) {
  // request 
  params = Object.assign({}, params, {
    methodName: "QueryProductReview"
  })

  // invoke
  this.$.get(params)
    .then(reshandler.success(success, fail, makeData), reshandler.error(fail))
}
